//
//  JKAction.m
//  zhongzhenglu
//
//  Created by 马军凯 on 2023/3/17.
//

#import "JKAction.h"

@implementation JKAction

//展示
+ (void)showTitle:(NSString *)title message:(NSString *)message btnArray:(NSArray <NSString *>*)btnArray completion:(void (^)(int index))completion {
    //创建alert
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
    //选择
    for (int i = 0; i < btnArray.count; i++) {
        UIAlertAction *btnAction = [UIAlertAction actionWithTitle:btnArray[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (completion) {
                completion(i);
            }
        }];
        [alertVC addAction:btnAction];
    }
    //取消
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertVC addAction:cancelAction];
    //显示
    [[UIApplication getCurrentVC] presentViewController:alertVC animated:YES completion:nil];
}

@end
